package com.ax.base.drugproducer.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ax.base.common.domain.Tree;
import com.ax.base.drugproducer.domain.BaseDrug;
import com.ax.base.system.domain.MenuDO;

@Mapper
public interface BaseDrugMapper {
    int deleteByPrimaryKey(Long drugId);

    int insert(BaseDrug record);

    @Insert("<script>"+
      "insert into base_drug (Drug_ID, Drug_Name, Drug_Alias,"+ 
	      "Spec, First_Letter, Drug_Class_Code,"+ 
	      "Drug_Class_Name, Is_Hemp, Component,"+ 
	      "Properties, Functions, Taboo,"+ 
	      "Attention, Producer_ID, Producer_Name,"+
	      "Usages, Adverse_Reaction, Storages,"+ 
	      "Validity_Term, Bar_Code, Approval_number,"+ 
	      "Instructions, Remarks, create_date,"+ 
	      "update_date, Flag,Drug_Interaction,Packing,Price,Is_Recipe)"+
	      "values (#{drugId}, #{drugName}, #{drugAlias},"+ 
	      "#{spec}, #{firstLetter}, #{drugClassCode},"+ 
	      "#{drugClassName}, #{isHemp}, #{component},"+
	      "#{properties}, #{functions}, #{taboo},"+ 
	      "#{attention}, #{producerId}, #{producerName},"+
	      "#{usages}, #{adverseReaction}, #{storages},"+
	      "#{validityTerm}, #{barCode}, #{approvalNumber},"+ 
	      "#{instructions}, #{remarks}, NOW(),"+ 
	      "#{updateDate}, #{flag},#{drugInteraction},#{packing},#{price},#{isRecipe})"+
    	  "</script>")
    int insertSelective(BaseDrug record);

    /**
	 * 药品修改(模块:药品)*跳转修改页面
	 * 
	 * @param Long id
	 *           
	 * @return HTML
	 */
    @Select("<script>"+
    		"select "+
    		"Drug_ID, Drug_Name, Drug_Alias, Spec, First_Letter, Drug_Class_Code, Drug_Class_Name,"+ 
    	    "Is_Hemp, Component, Properties, Functions, Taboo, Attention, Producer_ID, Producer_Name,"+ 
    	    "Usages, Adverse_Reaction, Storages, Validity_Term, Bar_Code, Approval_number, Instructions,"+ 
    	    "Remarks, create_date, update_date, Flag,Drug_Interaction,Packing,Price,Is_Recipe "+
    	    "from base_drug"+
    	    "<where>" + 
    	  	"<if test=\"drugId != null\">"+ "and Drug_ID = #{drugId} " + "</if>" + 
    	  	"</where>"+
    		"</script>")
    BaseDrug selectByPrimaryKey(@Param("drugId") Long drugId);

    /**
	 * 药品修改(模块:药品)
	 * 
	 * @param BaseDrug baseDrug
	 *           
	 * @return SUCC
	 */
    @Update("<script>"+
    		"update base_drug"+
    	    "<set>"+
    	    "<if test=\"drugName != null and drugName != ''\">"+ "Drug_Name = #{drugName}, " + "</if>" +
    	    "<if test=\"drugAlias != null and drugAlias != ''\">"+ "Drug_Alias = #{drugAlias}, " + "</if>" +
    	    "<if test=\"spec != null and spec != ''\">"+ "Spec = #{spec}, " + "</if>" +
    	    "<if test=\"firstLetter != null and firstLetter != ''\">"+ "First_Letter = #{firstLetter}, " + "</if>" +
    	    "<if test=\"drugClassCode != null and drugClassCode != ''\">"+ "Drug_Class_Code = #{drugClassCode}, " + "</if>" +
    	    "<if test=\"drugClassName != null and drugClassName != ''\">"+ "Drug_Class_Name = #{drugClassName}, " + "</if>" +
    	    "<if test=\"isHemp != null\">"+ "Is_Hemp = #{isHemp}, " + "</if>" +
    	    "<if test=\"component != null and component != ''\">"+ "Component = #{component}, " + "</if>" +
    	    "<if test=\"properties != null and properties != ''\">"+ "Properties = #{properties}, " + "</if>" +
    	    "<if test=\"functions != null and functions != ''\">"+ "Functions = #{functions}, " + "</if>" +
    	    "<if test=\"taboo != null and taboo != ''\">"+ "Taboo = #{taboo}, " + "</if>" +
    	    "<if test=\"attention != null and attention != ''\">"+ "Attention = #{attention}, " + "</if>" +
    	    "<if test=\"producerId != null\">"+ "Producer_ID = #{producerId}, " + "</if>" +
    	    "<if test=\"producerName != null and producerName != ''\">"+ "Producer_Name = #{producerName}, " + "</if>" +
    	    "<if test=\"usages != null and usages != ''\">"+ "Usages = #{usages}, " + "</if>" +
    	    "<if test=\"adverseReaction != null and adverseReaction != ''\">"+ "Adverse_Reaction = #{adverseReaction}, " + "</if>" +
    	    "<if test=\"storages != null and storages != ''\">"+ "Storages = #{storages}, " + "</if>" +
    	    "<if test=\"validityTerm != null and validityTerm != ''\">"+ "Validity_Term = #{validityTerm}, " + "</if>" +
    	    "<if test=\"barCode != null and barCode != ''\">"+ "Bar_Code = #{barCode}, " + "</if>" +
    	    "<if test=\"approvalNumber != null and approvalNumber != ''\">"+ "Approval_number = #{approvalNumber}, " + "</if>" +
    	    "<if test=\"instructions != null and instructions != ''\">"+ "Instructions = #{instructions}, " + "</if>" +
    	    "<if test=\"remarks != null and remarks != ''\">"+ "Remarks = #{remarks}, " + "</if>" +
    	    "<if test=\"createDate != null\">"+ "create_date = #{createDate}, " + "</if>" +
    	    "<if test=\"drugInteraction != null\">"+ "Drug_Interaction = #{drugInteraction}, " + "</if>" +
    	    "<if test=\"packing != null\">"+ "Packing = #{packing}, " + "</if>" +
    	    "<if test=\"price != null\">"+ "Price = #{price}, " + "</if>" +
    	    "<if test=\"isRecipe != null\">"+ "Is_Recipe = #{isRecipe}, " + "</if>" +
    	    "update_date = NOW(),"+
    	    "<if test=\"flag != null\">"+ "Flag = #{flag}, " + "</if>" +
    	    "</set>"+
    	    "where Drug_ID = #{drugId,jdbcType=BIGINT}"+
    		"</script>")
    int updateByPrimaryKeySelective(BaseDrug record);

    int updateByPrimaryKey(BaseDrug record);
    
    /**
	 * 药品查询(模块:药品)*包含药品的药品分类信息
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return PageUtils
	 */
    @Select("<script>"+
    		"select "+
    		"Drug_ID, Drug_Name, Drug_Alias, Spec, First_Letter, Drug_Class_Code, Drug_Class_Name,"+ 
    	    "Is_Hemp, Component, Properties, Functions, Taboo, Attention, Producer_ID, Producer_Name,"+ 
    	    "Usages, Adverse_Reaction, Storages, Validity_Term, Bar_Code, Approval_number, Instructions,"+ 
    	    "Remarks, create_date, update_date, Flag,Drug_Interaction,Packing,Price,Is_Recipe "+
    	    "from base_drug"+
    	    "<where>" + 
    	  	"<if test=\"drugId != null\">"+ "and Drug_ID = #{drugId} " + "</if>" + 
    	  	"<if test=\"drugClassCode != null and drugClassCode != ''\">"+ "and Drug_Class_Code = #{drugClassCode} " + "</if>" + 
    	  	"</where>"+
    	    /*"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+*/
    		"</script>")
    List<BaseDrug> queryDrugMapper(Map<String,Object> map);
    
    /**
	 * 药品查询分页总计
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return Integer
	 */
    @Select("<script>"+
    		"select "+
    		"count(0) "+
    	    "from base_drug"+
    	    "<where>" + 
    	  	"<if test=\"drugId != null\">"+ "and Drug_ID = #{drugdrugIdClassId} " + "</if>" + 
    	  	"<if test=\"drugClassCode != null and drugClassCode != ''\">"+ "and Drug_Class_Code = #{drugClassCode} " + "</if>" + 
    	  	"</where>"+
    		"</script>")
    Integer count(Map<String,Object> map);
    
    /**
	 * Tree
	 * 
	 * @param 无
	 *           
	 * @return List<Tree<MenuDO>>
	 */
    @Select("SELECT Drug_Class_ID id,concat_ws('-',Drug_Class_Name,Drug_Class_Code) text, Parent_Class_ID parentId FROM base_drug_class")
    List<Tree<MenuDO>> listClass();
}